import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/control',
    component: Layout,
    redirect: '/control/controllist',
    alwaysShow: true,
    name: 'Control',
    meta: { title: '权限管理', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'controllist',
        name: 'Controllist',
        component: () => import('@/views/control/controllist'),
        meta: { title: '账号管理', icon: 'el-icon-user' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/control/role'),
        meta: { title: '权限管理', icon: 'el-icon-user' }
      },
      {
        path: 'zygl',
        name: 'Zygl',
        component: () => import('@/views/control/zygl'),
        meta: { title: '资源管理', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    redirect: '/product/productlist',
    alwaysShow: true,
    name: 'Product',
    meta: { title: '商品管理', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'productlist',
        name: 'Productlist',
        component: () => import('@/views/product/productlist'),
        meta: { title: '商品列表', icon: 'el-icon-user' }
      },
      {
        path: 'classify',
        name: 'Classify',
        component: () => import('@/views/product/classify'),
        meta: { title: '商品分类', icon: 'el-icon-user' }
      },
      {
        path: 'brand',
        name: 'Brand',
        component: () => import('@/views/product/brand'),
        meta: { title: '品牌管理', icon: 'el-icon-user' }
      },
      {
        path: 'addproduct',
        name: 'Addproduct',
        hidden: true,
        component: () => import('@/views/product/addproduct'),
        meta: { title: '新增商品', icon: 'el-icon-user', activeMenu: '/product/productlist'}
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/isorder',
    name: 'Order',
    meta: { title: '订单管理', icon: 'el-icon-s-order' },
    children: [
      {
        path: 'isorder',
        name: 'Isorder',
        component: () => import('@/views/order/isorder'),
        meta: { title: '订单列表', icon: 'el-icon-document-checked' }
      },
      {
        path: 'delorder',
        name: 'Delorder',
        component: () => import('@/views/order/delorder'),
        meta: { title: '退单列表', icon: 'el-icon-document-delete' }
      },
      {
        path: 'live',
        name: 'Live',
        // hidden: true ,
        component: () => import('@/views/order/live'),
        meta: { title: '地址管理', icon: 'el-icon-office-building', }
      },
      {
        path: 'orderxq',
        name: 'Orderxq',
        hidden: true,
        component: () => import('@/views/order/orderxq'),
        meta: { title: '地址管理', icon: 'el-icon-office-building', activeMenu: '/order/isorder' }
      },
      {
        path: 'delorderlist',
        name: 'Delorderlist',
        hidden: true,
        component: () => import('@/views/order/delorder/delorderlist'),
        meta: { title: '地址管理', icon: 'el-icon-office-building', activeMenu: '/order/delorder' }
      }
    ]
  },
  
  
  {
    path: '/myd',
    component: Layout,
    redirect: '/myd/mydlist',
    alwaysShow: true,
    name: 'Myd',
    meta: { title: '注册用户列表', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'mydlist',
        name: 'Mydlist',
        component: () => import('@/views/myd/mydlist'),
        meta: { title: '用户列表', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/marketing',
    component: Layout,
    redirect: '/marketing/activity',
    alwaysShow: true,
    name: 'Marketing',
    meta: { title: '营销管理', icon: 'el-icon-folder-opened' },
    children: [
      {
        path: 'activity',
        name: 'Activity',
        component: () => import('@/views/marketing/activity'),
        meta: { title: '限时活动', icon: 'el-icon-goods' }
      },
      {
        path: 'slogan',
        name: 'Slogan',
        component: () => import('@/views/marketing/slogan'),
        meta: { title: '广告列表', icon: 'el-icon-folder' }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '内容管理', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/article/article'),
        meta: { title: '文章列表', icon: 'table' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/article/fodder'),
        meta: { title: '素材列表', icon: 'tree' }
      },
      {
        path: 'addarticle',
        name: 'Addarticle',
        hidden: true,
        component: () => import('@/views/article/addarticle'),
        meta: { title: '编辑文章', icon: 'tree', activeMenu: '/example/table' }
      },
    ]
  },




  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
